package three;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.MessageProperties;
import utils.RabbitMQUtils;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;
import java.util.concurrent.TimeoutException;

public class Task02 {
    public static final String QUEUE_NAME = "ACK_QUEUE";

    public static void main(String[] args) throws IOException, TimeoutException {
        Channel channel = RabbitMQUtils.getChannel();

        //声明队列
        channel.queueDeclare(QUEUE_NAME,true,false,false,null);
        //在控制台输入信息
        Scanner scanner =new Scanner(System.in);
        System.out.println("请输入信息:");
        while (scanner.hasNext()){
            String message = scanner.nextLine();
            //第二个参数 消息持久化

            channel.basicPublish("",QUEUE_NAME, MessageProperties.PERSISTENT_TEXT_PLAIN,message.getBytes(StandardCharsets.UTF_8));
            System.out.println("生产者发出消息" + message);
        }

    }
}
